home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / NEWSOFT / AUGUST / WORKDISC / !Forthmacs / lib / hexify < prev    next >
Text File  |  1997-04-04  |  1KB  |  55 lines

  1. \ This program converts a binary file into a form suitable for downloading
  2. \ to a Data-IO prom programmer.  The format used is Intel Hex Format,
  3. \ which is select code 83 on the Data-IO.
  4. \ To use:
  5. \ % forth hexify.fth -s "hexify your-binary-file-name" >filename.hex
  6.  
  7. \ TODO: use new record formats to support >64K:
  8. \ : bb AAAA 02 SSSS dd dd dd dd ... cc          Address is (SSSS <  4) + AAAA
  9. \ : bb AAAA 04 HHHH dd dd dd dd ... cc          Address is (HHHH < 16) + AAAA
  10. \ The SSSS and HHHH portions of the address are "sticky", applying to
  11. \ subsequent (type 00) records.
  12.  
  13. hex
  14.  
  15. 10 constant bytes/line
  16. variable out-addr
  17. create line-buf 64 allot
  18. variable outfile
  19. variable checksum
  20. variable end-of-file?
  21.  
  22. : .2    (s u -- )    h# ff and s>d <# # # #> 2dup upper type  ;
  23. : .4    (s u -- )    s>d <# # # # # #> 2dup upper type  ;
  24.  
  25. : get-line
  26.     bytes/line 0 do h# ff line-buf i + c! loop
  27.     bytes/line 0
  28.     do    ifd @  fgetc  dup -1 =
  29.         if    drop  end-of-file? on  leave
  30.         else    line-buf i + c!
  31.         then
  32.     loop ;
  33. : put-line
  34.     bytes/line  checksum !
  35.     ." :"  bytes/line .2
  36.     out-addr @ 8 rshift h# ff and checksum +!
  37.     out-addr @ h# ff and checksum +!
  38.     out-addr @ .4 ." 00"
  39.     bytes/line  0
  40.     do    line-buf i + c@  dup checksum +!  .2
  41.     loop
  42.     checksum @ ff and  100 swap -  .2 cr
  43.     bytes/line out-addr +! ;
  44. : (hexify    ( -- )
  45.     end-of-file? off
  46.     0 out-addr !
  47.     begin    get-line  put-line
  48.         end-of-file? @
  49.     until
  50.     ." :00000001FF" cr
  51.     ifd @ fclose ;
  52. : hexify    ( "input-file-name" -- )
  53.     hex reading (hexify  ;
  54.